import {connect} from 'react-redux'
import * as TodoActions from '../store/action/todos'
import * as FilterActions from '../store/action/visibilityFilter'
import App from '../components/TodoApp'


function mapStateToProps(state, props) {
    console.log(state);
    return {
        todos: state.todos,
        filter: state.visibilityFilter
    }
}

function mapDispatchToProps(dispatch) {
    return {
        onDeleteTodo: (id) => dispatch(TodoActions.delTodo(id)),
        onAddTodo: (text) => dispatch(TodoActions.addTodo(text)),
        onToggleTodo: (id) => dispatch(TodoActions.toggleTodo(id)),
        onChangeTodo: (id, text) => dispatch(TodoActions.changeTodo(id, text)),
        onToggleAll: (toggle) => dispatch(TodoActions.toggleAll(toggle)),
        onClearCompletedTodo:()=>dispatch(TodoActions.clearCompletedTodo()),

        onChangeVisibilityFilter: (filter) => dispatch(FilterActions.changeVisibilityFilter(filter)),
    };
}

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(App)